let product_yh_controller = {
    // productList.html 查询所有的商品信息(SPU)
    findGoodsAll: function (pageNum,pageSize) {
        axios({
            url:"/admin/goods",
            method:"GET",
            params:{
                server: "goods",
                pageNum: pageNum,
                pageSize: pageSize
            }
        }).then(function (value) {
            // console.log(value.data.data);
            if (value.data.code == 200) {
                vueapp.page = value.data.data;
                vueapp.goodsList = value.data.data.list;
            } else {
                alert(value.data.msg)
            }
        })
    },
    // productList.html 修改商品(spu)的状态
    updateGoodsStatus: function (goodsId,state) {
        axios({
            url:"/admin/goods/update",
            method:"POST",
            params: {
                server: "goodsState",
                goodsId: goodsId,
                state: state,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                location.reload(location.href);
            } else {
                alert(value.data.msg)
            }
        })
    },
    // productList.html 提示框
    downPromptBox: function() {
        alert("商品已被下架，无法操作该功能")
    },

    // itemProductList.html/goodsDetails.html 查询商品所有的详细规格产品(sku)
    findItemFromGoodsId: function (goodsId,excludeDel) {
        axios({
            url:"/admin/goods",
            method:"GET",
            params:{
                server: "items",
                excludeDel: excludeDel,
                goodsId: goodsId,
            }
        }).then(function (value) {
            // console.log(value.data.data);
            if (value.data.code == 200) {
                vueapp.itemList = value.data.data;
            } else {
                alert(value.data.msg)
            }
        })
    },
    // itemProductList.html 修改商品(sku)的状态
    updateItemStatus: function(itemId,state) {
        axios({
            url:"/admin/goods/update",
            method:"POST",
            params: {
                server: "itemState",
                itemId: itemId,
                state: state,
            }
        }).then(function (value) {
            if (value.data.code == 200) {
                location.reload(location.href);
            } else {
                alert(value.data.msg)
            }
        })
    },
    // itemProductList.html 提示框
    promptBox: function() {
        alert("单品已被绑定，暂不支持该操作")
    },
    // itemProductList.html 删除所有选中的商品
    delAll: function () {
        var array = new Array();
        // 获取所有的复选框
        var checks = document.getElementsByName("check");
        for (i=0; i<checks.length; i++) {
            var check = checks[i];
            // 获取所有选中的复选框的值
            if (check.checked == true) {
                array.push(check.value);
            }
        }
        axios({
            url:"/admin/goods/update",
            method:"POST",
            params: {
                server: "delAll",
                state: '3',
            },
            data: array
        }).then(function (value) {
            if (value.data.code == 200) {
                location.reload(location.href);
            } else {
                alert(value.data.msg)
            }
        })
    },

    // productDetails.html 根据ID精确查询单品信息(sku)
    findItemfromId: function (itemId) {
        axios({
            url:"/admin/goods",
            method:"GET",
            params:{
                server: "item",
                itemId: itemId,
            }
        }).then(function (value) {
            // console.log(value.data.data);
            if (value.data.code == 200) {
                vueapp.item = value.data.data;
            } else {
                alert(value.data.msg)
            }
        })
    },
    // productDetails.html 修改单品信息(sku)
    updateItem: function (itemId) {
        var item = this.item
        // 在v-model未更新数据的情况下，手动取值和赋值
        var colour = document.getElementById("colour").value;
        var network = document.getElementById("network").value;
        var runMemoryId = document.getElementById("yxnc").value;
        var fuselageMemoryId = document.getElementById("jsnc").value;
        item.colour = colour;
        item.network = network;
        item.runMemoryId = runMemoryId;
        item.fuselageMemoryId = fuselageMemoryId;
        // 正式请求服务器修改数据
        axios({
            url:"/admin/goods/update",
            method:"POST",
            params: {
                server: "item",
            },
            data: item,
        }).then(function (value) {
            if (value.data.code == 200) {
                location.reload(location.href);
            } else {
                alert(value.data.msg)
            }
        })
    },

    // goodsDetails.html 修改商品信息(spu)
    updateGoods: function (itemId) {
        var goods = this.goods
        // 在v-model未更新数据的情况下，手动取值和赋值；注意0号位储存的是规格名称，我们应该储存产品默认的规格参数ID，即1号位
        goods.map.qzsxt[1] = document.getElementById("qzsxt").value;
        goods.map.hzsxt[1] = document.getElementById("hzsxt").value;
        goods.map.spzl[1] = document.getElementById("spzl").value;
        goods.map.zpcc[1] = document.getElementById("zpcc").value;
        goods.map.cpu[1] = document.getElementById("cpu").value;
        goods.map.xtnh[1] = document.getElementById("xtnh").value;
        goods.map.sim[1] = document.getElementById("sim").value;
        goods.map.dcrl[1] = document.getElementById("dcrl").value;
        goods.brandId = document.getElementById("brand").value;
        goods.defaultItemId = document.getElementById("defaultItem").value;
        // 正式请求服务器修改数据
        axios({
            url:"/admin/goods/update",
            method:"POST",
            params: {
                server: "goods",
            },
            data: goods,
        }).then(function (value) {
            if (value.data.code == 200) {
                location.reload(location.href);
            } else {
                alert(value.data.msg)
            }
        })
    },

    // addProduct.html/goodsDetails.html 查询单个商品信息(SPU)
    findGoodsById: function (goodsId) {
        axios({
            url:"/admin/goods",
            method:"GET",
            params:{
                server: "goodsFromId",
                goodsId: goodsId,
            }
        }).then(function (value) {
            // console.log(value.data.data);
            if (value.data.code == 200) {
                vueapp.goods = value.data.data;
            } else {
                alert(value.data.msg)
            }
        })
    },
    
    // 回显所有的品牌
    findBrandAll: function () {
        axios({
            url:"/selectbrand",
            method:"GET",
            params:{
                server: "findbrandall",
            }
        }).then(function (value) {
            console.log(value.data.data);
            if (value.data.code == 200) {
                vueapp.brandList = value.data.data;
            } else {
                alert(value.data.msg)
            }
        })
    },
    // 回显所有的规格
    findSpeciAll: function () {
        axios({
            url:"/selectspecification",
            method:"GET",
            params:{
                server: "findspecificationall",
            }
        }).then(function (value) {
            console.log(value.data.data);
            if (value.data.code == 200) {
                vueapp.speciList = value.data.data;
            } else {
                alert(value.data.msg)
            }
        })
    }
}